import defaultSettings from '@/settings/projectSetting'
const { showSettings, tagsView, fixedHeader, sidebarLogo, uniqueOpened, showFooter, footerTxt, caseNumber, sidebarLayout, title } = defaultSettings
import Cookies from 'js-cookie'

import { ActionContext } from 'vuex'
import { State, RootState } from '@vue/runtime-core'

const state = {
  theme: Cookies.get('theme') ? Cookies.get('theme') : '$--colors-primary',
  showSettings: showSettings,
  tagsView: tagsView,
  fixedHeader: fixedHeader,
  sidebarLogo: sidebarLogo,
  uniqueOpened: uniqueOpened,
  showFooter: showFooter,
  footerTxt: footerTxt,
  caseNumber: caseNumber,
  sidebarLayout: Cookies.get('sidebarLayout') ? Cookies.get('sidebarLayout') : sidebarLayout,
  title: title
}

const mutations = {
  CHANGE_SETTING: (state: State, { key, value }: any) => {
    Cookies.set(key, value)

    if (Object.prototype.hasOwnProperty.call(state, key)) {
      state[key] = value
    }
  }
}

const actions = {
  changeSetting({ commit }: ActionContext<State, RootState>, data: Object | string) {
    commit('CHANGE_SETTING', data)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
